package com.wisty.finalproject;

import java.util.ArrayList;

import org.json.JSONObject;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.HttpMethod;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.model.GraphObject;

public class EventDisplayMessageActivity extends Activity {
	
	private boolean checkLike = false;
	private boolean checkJoin = false;
	
	private String[] userId = {"100000212223009","100000464403538"};
	private String[] commentData = {"100000212223009","chen"};
	
	private ArrayList<CommentModel> commentList = new ArrayList<CommentModel>();
	private ListView commentListView;
	private CommentAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_event_display_message);
		// Show the Up button in the action bar.
		setupActionBar();
		
		// Get the message from the intent
	    Intent intent = getIntent();
	    String name = intent.getStringExtra("name");
	    String date = intent.getStringExtra("date");
	    String time = intent.getStringExtra("time");
	    String location = intent.getStringExtra("location");
	    String description = intent.getStringExtra("description");
	    
	    TextView nameView = (TextView) findViewById(R.id.event_inside_name);
	    TextView dateView = (TextView) findViewById(R.id.event_inside_start_date);
	    TextView timeView = (TextView) findViewById(R.id.event_inside_start_time);
	    TextView locationView = (TextView) findViewById(R.id.event_inside_location);
	    TextView descriptionView = (TextView) findViewById(R.id.event_inside_description);
	    ImageView image = (ImageView) findViewById(R.id.event_inside_picture);
	    
	    nameView.setText(name);
	    dateView.setText(date);
	    timeView.setText(time);
	    locationView.setText(location);
	    descriptionView.setText(description);
	    
	    Bundle extras = getIntent().getExtras();
	    Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");

	    image.setImageBitmap(bmp );
	    Switch like = (Switch) findViewById(R.id.event_inside_switch_like);
	    like.setChecked(intent.getBooleanExtra("like", false));
    	like.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    	    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    	        if (isChecked) {
    	        	checkLike = true;
    	        	Log.i("like","true");
    	            // The toggle is enabled
    	        } else {
    	        	checkLike = false;
    	  	        Log.i("like","false");
    	            // The toggle is disabled
    	        }
    	    }
    	});
    	if(like.isChecked()){
    		checkLike = true;
        	Log.i("like","true");
    	}
    	else{
    		checkLike = false;
  	        Log.i("like","false");
    	}
    	Switch join = (Switch) findViewById(R.id.event_inside_switch_join);
    	join.setChecked(intent.getBooleanExtra("join", false));
    	join.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    	    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    	        if (isChecked) {
    	        	checkJoin = true;
    	        	Log.i("join","true");
    	            // The toggle is enabled
    	        } else {
    	        	checkJoin = false;
    	  	        Log.i("join","false");
    	            // The toggle is disabled
    	        }
    	    }
    	});
    	if(join.isChecked()){
    		checkJoin = true;
        	Log.i("join","true");
    	}
    	else{
    		checkJoin = false;
  	        Log.i("join","false");
    	}
    	/*commentListView = (ListView) findViewById(R.id.CommentListView);
         
 	    
        // create a custom adapter and set to the list view
        adapter = new CommentAdapter(this, commentList);
        commentListView.setAdapter(adapter);*/
    	/*Bundle bundle = new Bundle();  
        bundle.putBoolean("like", checkLike);
        bundle.putBoolean("join", checkJoin);
        Intent intentsend = new Intent();  
        intent.putExtras(bundle);  
        setResult(RESULT_OK, intentsend);  
        finish();  */
	    
	}

	/**
	 * Set up the {@link android.app.ActionBar}, if the API is available.
	 */
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	private void setupActionBar() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
			getActionBar().setDisplayHomeAsUpEnabled(true);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.event_display_message, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		case R.id.add_comment :
			 
            
            Toast.makeText(getBaseContext(), "123", Toast.LENGTH_SHORT).show();
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	private void makeUserRequest(final Session session,String id) {
        // Make an API call to get user data and define a 
        // new callback to handle the response.
		new Request(
			    session,
			    "/"+id,
			    null,
			    HttpMethod.GET,
			    new Request.Callback() {
			        public void onCompleted(Response response) {
			            /* handle the result */
			        	try{
			        		GraphObject go  = response.getGraphObject();
	    		            JSONObject  jso = go.getInnerJSONObject();
	    		            String user = jso.getString("id");
				        	CommentModel comment = new CommentModel();
			        	}
			        	catch ( Exception e )
	    		        {
	    		                e.printStackTrace();
	    		        }
			        }
			    }
			).executeAsync();
    }
}
